<?php
class theme {
    /**
     *main Object
     */
    static $ci;

    private static $widget = array();

    private static $module = "";

    private static $template = "";

    private static $path = "";

    private static $title = "";


    /**
     *@method void contruc
     */
    function theme() {
        self::$ci =& get_instance();
        self::$ci->load->library('parser');
        self::$widget['title'] = "";
        self::$widget['css_links'] = "";
        self::$widget['javascript_links'] = "";
    }
    /**
     *@method void set_css($link) set css link
     *@param string css link
     -----------------------------------------------------------------------*/
    public static function set_css($link) {
        $link = '<link href="'.$link.'" rel="stylesheet" type="text/css">';
        self::$widget['css_links'] .= $link;
    }

    /**
     *@method void set_javascript
     *@param string $link/ array $links
     -----------------------------------------------------------------------*/
    public static function set_javascript($link) {
        $link = '<script src="'.$link.'" type="text/javascript" ></script>';
        self::$widget['javascript_links'] .= $link;
    }

    /**
     *@todo set title
     *@access public
     *@param string $title
     -----------------------------------------------------------------------*/
    public static function set_title($title) {
        self::$title = $title;
        self::$widget['title'] = self::$title;
    }

    /**
     *@todo set mainpage
     *@param string $filename
     ------------------------------------------------------------------------*/
    public static function set_template($filename) {
        self::$template = $filename; 
    }

    /**
     *@todo set mainpage
     *@param string $filename
     ------------------------------------------------------------------------*/
    public static function set_mainpage($filename) {
        self::set_template($filename);
    }

    public static function set_widget_folder($string = "") {
        self::$folder = $string;
    }

    /**
     *@todo set module name
     *@param string $module
     ------------------------------------------------------------------------*/
    public static function set_module($module) {
        self::$module = $module;
        self::$path = APPPATH."modules/".self::$module . "/views/";
    }
    /**
     *@todo set widget content to mainpage with param
     *@param string $file_widget
     *@param string $to widget name on main page
     *@param $data
     ------------------------------------------------------------------------*/
    public static function set_widget($file_widget, $to ,$data = array()) {
        $full_path = self::$path.$file_widget.EXT;
        if(file_exists($full_path)) {
            if(!isset(self::$widget[$to])) {
                self::$widget[$to] = self::$ci->load->view($file_widget,$data,true);
            }else {
                self::$widget[$to] .= self::$ci->load->view($file_widget,$data,true);
            }
        }else {
            self::$widget[$to] = 'Error: Can not set widget, please check file name: "'.$full_path.'"';
        }
    }

    /**
     *@todo Out theme
     *@access public
     *@param void
     -------------------------------------------------------------------------*/
    public static function render() {
        if(file_exists(self::$path.self::$template.EXT)) {
            self::$ci->parser->parse(self::$template,self::$widget);
        }else {
            show_error("class template Error: Can not set mainpage ".self::$template);
        }

    }

    public static function out() {
        self::render();
    }

    function __destruct() {

    }
}
?>